home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / misc / fpl-v13.lha / fpl / docs / FPLlib.doc < prev    next >
Text File  |  1995-03-01  |  34KB  |  924 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.                                      FPL
  7.  
  8.  
  9.                                    Version
  10.                                        
  11.  
  12.  
  13.  
  14.  
  15.                                        
  16.  
  17.  
  18.  
  19.                                        
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.                          Generated with Heddley v1.1
  37.                       Heddley v1.1 (C) Edd Dumbill 1994
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.                                   - Page 1 -
  77.  
  78.  
  79.  
  80. 1.    FPL Library Documentation
  81.  
  82.  FPL is Copyright © 1992-1994 by  FrexxWare . Permission is granted to freely
  83. distribute this program for non-commercial purposes only. FPL is distributed
  84. "as is"  without warranty  of any kind.
  85.  
  86.  For you who'd like to know about the FPL language, installation, warranty,
  87. bug report address and other things refer to  FPL programming! 
  88.  
  89.  For all the rest, who you want to implement fpl.library support in your
  90. program...
  91.  
  92.    Survey               - short overview to get an idea of what FPL is about
  93.    Multi file concepts  - how to enable cross file function calls with FPL
  94.    Implement guide      - step by step guide how to implement FPL library
  95.    Coding hints         - general information
  96.    Error exceptions     - errors that you are responsible of
  97.    Custom functions     - functions you supply FPL to take care of things
  98.    Using in software    - rules about using FPL in your software
  99.  
  100. [Amiga only]
  101.    Funclib overview     - use/create shareable third party FPL functions
  102.  
  103. 2.    Funclib overview
  104.  
  105.   From fpl.library version 7, there is 'funclib' support added. Funclibs are
  106. simply programs that add functions to a running FPL session. The funclibs
  107. should be placed in FPLLIBS: and are opened by an FPL program or through the
  108. fpl.library function 'fplOpenLib()'.
  109.  
  110.   Funclibs are nothing but common executable files that are run (with a
  111. specified parameter setup) by FPL. The program adds functions to the FPL
  112. session that opened the lib just like any other program. The functions are
  113. removed again when the funlib is closed. For details in how to program such a
  114. funclib, check out the files in the funclib/ directory of the FPL distribution
  115. package.
  116.  
  117.   Funclibs work much like shared libraries (in the eyes of the FPL programmer)
  118. with an open counter that increases for multiple opens, and decreases on each
  119. close until it reaches zero and then is removed. Funclibs that are opened with
  120. the library function can be opened in such a way that it isn't possible to
  121. close it (decrease the counter to zero) from within an FPL program, but must
  122. be closed by the library function 'fplCloseLib()'.
  123.  
  124.   All funclibs are automatically closed when the 'fplFree()' function is
  125. called.
  126.  
  127. 3.    Using FPL in software
  128.  
  129. FPL copyright (C) by FrexxWare and is freely distributed for non-commercial
  130. purposes only.
  131.  
  132. You may include the FPL library in your freely distributed program for free,
  133. but make sure to include the FPL.README file and, at your option, the
  134. FPLuser.guide/FPLuser.ASCII. The included files must remain unmodified.
  135.  
  136. Freely distributed programs are such programs that are Shareware, Freeware,
  137. Giftware, Public domain and likewise. Please make it very clear in your
  138. ditribtution documentation that FPL is nothing but Freeware, no matter what
  139. the state of the rest of your software package is!
  140.  
  141. Commercial programs may not include FPL without written permission from the
  142. author! I will also require a fee to allow FPL in commercial software, since
  143. such programs are done to earn money, and my creation contributes to that.
  144.  
  145. I erge *all* implementors of FPL to write me a short note when you decide to
  146.  
  147.                                   - Page 2 -
  148. 3.    Using FPL in software
  149.  
  150. include this library in your software. I really would like to keep track of
  151. the amount of programs using FPL. It also gives me a possibility to inform you
  152. about new releases and such things. Please include your opinions about FPL in
  153. your "notify mail". I use your criticism as guide in which directions I should
  154. develop FPL, which features I should prioritize and which I shouldn't!
  155.  
  156. 4.    Multi files concepts
  157.  
  158.     What is the multi file system?
  159.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  160.  The multi file system allows FPL program writing divided into any number of
  161. source files and calling FPL functions cross-file. A function defined and
  162. exported in one file may be called from another file's FPL program.
  163.  
  164.     How do you activate it?
  165.     ~~~~~~~~~~~~~~~~~~~~~~~
  166.  Multi file systems means that FPL has to know in which files which functions
  167. are found. As you know, all functions declared as `export' will be accessible
  168. from other files. To enable such functionality to the FPL programmer, you must
  169. either let FPL cache the files that export functions, or cache (keep track of)
  170. them by yourself. This is done by using the fplInit() tag FPLTAG_CACHEALLFILES
  171. (which sets the cache default on/off) or by specifying the fplExecuteXXXXX()
  172. tags FPLTAG_CACHEFILE (which enables/diables caching of this specific program)
  173. and FPLTAG_FILENAME (which tells FPL the name of this program). FPL programs
  174. must have names to get cached.
  175.  
  176.     File caching
  177.     ~~~~~~~~~~~~
  178.  The term "file caching" means that FPL will, if any global symbols were
  179. declared, remember that program. If the program was started with
  180. fplExecuteFile(), FPL will keep the entire program in memory and if it was
  181. invoked using fplExecuteScript(), FPL expects you to have the program
  182. accessible just as it is.
  183.  
  184.     File flush
  185.     ~~~~~~~~~~
  186.  When using cached files, you may end up with a lot of FPL programs cached,
  187. occupying a lot of memory. You can tell FPL to flush a specific file or all
  188. files not currently in use by calling fplSend() with the tag
  189. FPLSEND_FLUSHFILE. All files that FPL is in control over can then be removed
  190. from memory, and for every file that you have control over, a FPL_FLUSH_FILE
  191. argument ID will be sent to the interface function with ->argv[0] set to the
  192. name of that file. If you decide to flush such a program from memory, and
  193. removing the accessibility for FPL, it must be confirmed to FPL by using a
  194. {FPLSEND_CONFIRM, TRUE} tag to fplSend(). No confirmation means you didn't
  195. flush the file.
  196.  
  197.     Auto flush/get file
  198.     ~~~~~~~~~~~~~~~~~~~
  199.  Using fplExecuteFile() will set all flags to make FPL automatically load the
  200. file from disk again when it wants access a flushed file. By setting the
  201. fplExecuteXXXXX() tags FPLTAG_PROGNAME and FPLTAG_FILENAMEGET, you tell FPL
  202. that your program can be loaded with the program name as file name whenever it
  203. wants to access this specific file after a flush. Those flags can be added run
  204. time by FPLSEND_SETPROGNAME and FPLSEND_GETFILENAMEGET.
  205.  
  206. 5.    Important note
  207.  
  208.  
  209.   Most important of everything: USE THE INCLUDES AND THE VALUES AND STRUCTURES
  210. DEFINED IN THERE, cause if there is one thing I've learned, it is that I'm
  211. terribly good at changing things making a re-compile necessary when updating
  212. library version!
  213.  
  214. Amiga programming details:
  215.  
  216.     Indexing register
  217.  
  218.                                   - Page 3 -
  219. 5.    Important note
  220.  
  221.     ~~~~~~~~~~~~~~~~~
  222.  Compilers often have the cabability to produce output code that do address
  223. all data 16-bit indexed by an address register (standard SAS/C code uses A4).
  224. When fpl.library calls the interface or intercal function specified by you,
  225. that register will contain the same as it did when you called fplInit(). In
  226. all standard, normal cases this means the register is preserved just as you
  227. want it!
  228.  
  229.   Note that this is not true when dealing with the FPLTAG_INTERNAL_ALLOC and
  230. FPLTAG_INTERNAL_DEALLOC patches. If you want those functions to be able to
  231. access global data, you must re-load the indexing register. Some ways to do
  232. it:
  233.  
  234.   LATTICE C version 5.xx:
  235.     Use the -y flag (which forces A4 to be loaded in every function)
  236.     when compiling the functions called from within the library or
  237.     specify the keyword __saveds (in front of the function declaration)
  238.     to perform the same task. Compiling with -b0 *SHOULD* remove the
  239.     problem even though I have had problems trying this...
  240.  
  241.   SAS/C version 6.x
  242.     Like the above text. The compiler keywords affected are DATA=NEAR
  243.     instead of -b1 and SAVEDS instead of -y. The -b0 is equivalent to
  244.     DATA=FAR. Starting the functions (called from the library) with
  245.     "geta4();" will do the same too.
  246.  
  247.   Axtec C:
  248.     Start the functions with "geta4();".
  249.  
  250.   DICE:
  251.     Use the keyword __geta4 before the function name where you define/
  252.   declare it.
  253.  
  254.     Stack checks/expandings
  255.     ~~~~~~~~~~~~~~~~~~~~~~~
  256.   Were before version 9.5 not allowed/recommeded/working, but are now if not
  257. required at least recommended. Since 9.5, your program has to deal with its
  258. own stack, FPL only uses its own for internal use.
  259.  
  260.     Stack Usage
  261.     ~~~~~~~~~~~
  262.  fpl.library allocates and uses very little of the host process' stack (approx
  263. 200-300 bytes on the fplInit() and 100-200 bytes in other function calls). It
  264. uses mainly an own allocated stack with expanding possibilities!
  265.  
  266. 6.    Survey
  267.  
  268.   FPL interprets a common text file.  Expressions  are evaluated,  variables 
  269. declared,  keywords  executed. (Every time FPL finds a keyword or a closing
  270. brace, it calls an  interval function .)
  271.  
  272.   Whenever FPL finds a  function  name (and it's not one of the internal ones)
  273. that matches one of those you have told it to recognize, it parses the
  274. parameters as you have declared.
  275.  
  276.   If all parameters were read without problems, FPL initializes another
  277. structure and calls a function supplied by you, with a pointer to that
  278. structure as argument.
  279.  
  280.   You send return code to FPL and return from the function with the proper
  281. result code and FPL continues to interpret the text file.
  282.  
  283.   LOOP!
  284.  
  285. 7.    Step by step
  286.  
  287.   Let's take a step by step look at what you have to do to implement a real
  288.  
  289.                                   - Page 4 -
  290. 7.    Step by step
  291.  
  292. and working FPL interface. Start your favourite editor and edit your source
  293. while reading this!
  294.  
  295. 1. If your programming Amiga, open the library by simply doing:
  296.   "struct Library *FPLBase = OpenLibrary(FPLNAME, version);"
  297.  
  298. 2. Call the fplInit() function with proper arguments. 
  299.  
  300. 3. Inform FPL about all functions you want it to accept by calling the
  301.    fplAddFunction() for every function FPL should approve. Since version 10,
  302.    you can also add variables with fplAddVariable()!
  303.    See  adding functions to FPL !
  304.  
  305. 4. Code the  interface function . This function will get
  306.    called whenever FPL finds one of your predeclared functions or wants
  307.    something specific. There are a few  reserved messages  that this function
  308.    can receive and that it should answer/react to.
  309.  
  310. 5. Call fplExecuteScript() or fplExecuteFile() depending on how you have
  311.    your data stored.
  312.  
  313. 6. FPL takes control and performs:
  314.  
  315.  - FPL executes the program as fast as possible and whenever it finds a
  316.    function or variable that's not an internal, compares it with the ones
  317.    added by you.
  318.    If you hadn't specified it, FPL returns an error code.
  319.  
  320.  - If it is a function, FPL will check the argument string you specified for
  321.    that particular function and read the arguments according to that.
  322.  
  323.  - The interface function is called with the pointer to the  fplArgument  as
  324.    argument.
  325.  
  326.  - You return the function's result by using fplSend().
  327.  
  328.  - Every now and then (with very irregular intervals - after about every
  329.    statement in the program) the  interval function  will be
  330.    called, if specified!
  331.  
  332.  - If the  keyword   exit()  isn't found and there is more program to
  333.    execute, FPL continues.
  334.  
  335. 7. When completed, FPL returns a zero (0) if everything went ok, or an
  336.    error code. If FPL discovered an error, the interface function will be
  337.    called just before returning control to you, with the ID set to
  338.     FPL_GENERAL_ERROR .
  339.  
  340. 8.    Adding functions to FPL
  341.  
  342.   The very soul of FPL is to add functions that has no visual difference from
  343. the built-in functions. When such a function is used in an executed program,
  344. the ' interface function ' is called.
  345.  
  346.   Adding functions is done with the fplAddFunction() function with which you
  347. specify function name, return data type, number of parameters and their data
  348. types and a few other things. See fpl.doc for closer details.
  349.  
  350.   Since version 10, FPL also supports variable addings by calling
  351. fplAddVariable().
  352.  
  353. 9.    fplInit() calling
  354.  
  355. GENERAL
  356.   The very first action to do (Amiga: after you've opened "fpl.library"), or
  357. at least before you can or should use any other FPL library function,
  358. fplInit() must be called with the proper arguments.
  359.  
  360.                                   - Page 5 -
  361. 9.    fplInit() calling
  362.  
  363.  
  364.   fplInit() initializes the FPL session and tells FPL how you would like a few
  365. things to be in the soon coming FPL program executings.
  366.  
  367. FUNCTION
  368.  
  369.   The major things that you control with this function is of course the ones
  370. that can't be changed later on. Among those things are: (for more details,
  371. refer to the fpl.doc file)
  372.  
  373. * The function that is to be called on each discovered function and every
  374.   time FPL wants to tell you something. The function is called the
  375.   ' interface function '.
  376.  
  377. * Allocation and deallocation functions patches. You can change the function
  378.   FPL is using to get and leave memory to the system and the smoothest way
  379.   to use that is to tell fplInit() using certain tags.
  380.  
  381. * Hash table size. The size of the symbol hash table must be static during
  382.   an FPL session.
  383.  
  384. RESULT
  385.  
  386.   The return code of this function is the 'handle' which you must use when you
  387. call any of the other FPL library functions!
  388.  
  389. 10.    Errors
  390.  
  391.   Whenever an error occurs, the execution is halted and an error code
  392. returned. Error message is available by using the proper tag to fplInit() or
  393. fplExecuteXXXX(). The old and still working way is to use the fplGetErrorMsg()
  394. function.
  395.   Just before the FPL functions returns, the interface function is called with
  396. the  FPL_GENERAL_ERROR  ID.
  397.  
  398.   Most of the returned error codes is returned due to programming errors in
  399. the FPL code. Some is caused by your incompetent coding!
  400.  
  401. INTERNAL ERROR
  402.   Returned if you try to flush a non existing file or if FPL requested a
  403.   program from you, using the  FPL_REQUEST_FILE  ID
  404.   and no proper message were returned.
  405.  
  406. ILLEGAL ANCHOR
  407.   You called an FPL function with an illegal parameter!
  408.  
  409. FILE ERROR
  410.   Might be caused by you. This error code is returned when FPL has
  411.   trouble with any of the file related function on the specified file.
  412.   Only happens when using fplExecuteFile().
  413.   and most often if the specified file doesn't exist.
  414.  
  415. 11.    Your functions
  416.  
  417.  
  418.      Interface function 
  419.      Interval function  
  420.      Memory functions   
  421.  
  422. 12.    Memory functions
  423.  
  424.  To keep FPL as flexible and powerful as possible, you can supply a function
  425. pointer to a function that takes care of allocating/freeing memory instead of
  426. the internal FPL default functions.
  427.  
  428.  (Amiga) The free function will get the memory pointer in A1 and the size in
  429. D0, and the malloc function will get the size in D0. Both functions will get
  430.  
  431.                                   - Page 6 -
  432. 12.    Memory functions
  433.  
  434. the userdata in A1.
  435.  
  436.  This sounds more complicated than it really is. Let's take a look on a small
  437. example:
  438.  
  439.  You program a software product that allocates a large memory area at startup
  440. and then you handle all allocate/deallocate within your program inside that
  441. memory area. You open fpl.library and it would be nice if you could make that
  442. use the same memory area and allocating functions.
  443.  
  444.  Just use the tag  FPLTAG_INTERNAL_DEALLOC  and specify the free function and
  445.  FPLTAG_INTERNAL_ALLOC  to specify the allocate function. The functions could
  446. look something like this:
  447.  
  448.  (NOTE: the "__asm" and "register __xx" is Amiga and SAS/C specific keywords
  449. for receiving parameters into specified registers.)
  450.  
  451.   void __asm FPLfree(register __a1 void *pointer,
  452.                      register __d0 long size,
  453.                      register __a0 void *userdata)
  454.   {
  455.      extern int memory; /* external variable counting malloced memory */
  456.      MyFree(pointer);   /* free the memory using our own free() */
  457.      memory-=size;      /* decrease the memory counter */
  458.   }
  459.   
  460.   void __asm *FPLmalloc(register __d0 long size,
  461.                         register __a0 void *userdata)
  462.   {
  463.     extern int memory:  /* external variable counting malloced memory */
  464.     MyAlloc(size);      /* allocate with your own function */
  465.     memory+=size;       /* increase memory counter! */
  466.   }
  467.  
  468. and the fplInit() call to apply this could look like:
  469.  
  470.   void main(void)
  471.   {
  472.     unsigned long tags[]={
  473.       FPLTAG_INTERNAL_DEALLOC, (unsigned long)FPLfree,
  474.       FPLTAG_INTERNAL_ALLOC,   (unsigned long)FPLmalloc,
  475.       FPLTAG_DONE
  476.     };
  477.     void *anchor =  fplInit ( interfaceFunction , tags);
  478.   
  479.     /* and more should be added here */
  480.   }
  481.  
  482. 13.    Argument
  483.  
  484.   The argument points to a fplArgument structure which is telling you about
  485. the function. That structure and all the data of it, is strictly READ ONLY. Do
  486. not make any stupid moves. These are the members of the fplArgument
  487. structure:
  488.  
  489.   name  The name of the function. Zero terminated.
  490.  
  491.   ID    The number you associate with the function/variable. This has no
  492.         meaning to the library. This is the number that is sent in the ID
  493.         parameter in the fplAddFunction/fplAddVariable call.
  494.  
  495.         *ALL* negative ID numbers are reserved for FPL internal function
  496.         calls, queries and handlers. See the  reserved exception IDs .
  497.  
  498.   argv  This is a pointer to a void pointer array containing all
  499.         arguments specified in the FPL program to this function.
  500.         The arguments were read according to the "format" member of this
  501.  
  502.                                   - Page 7 -
  503. 13.    Argument
  504.  
  505.         structure informs us.
  506.  
  507.         Different argument types creates different
  508.         types of data:
  509.  
  510.         format letter   real data
  511.         -------------   ---------
  512.          FPL_STRARG     char pointer.
  513.          FPL_INTARG     integer.
  514.          FPL_OPTARG     char pointer OR integer
  515.          FPL_ARGLIST    Like the previous one. This tells the library to
  516.                         accept any number of that argument type. Compare to
  517.                         the `...' of the C programming language.
  518.  
  519.         When variables are read, this is set to zero (0).
  520.  
  521.   argc  Number of members in the argv array described above.
  522.  
  523.   key   This is the same pointer you received when you called fplInit().
  524.         This can be used to get information with eg. fplSend() and even to
  525.         add/delete functions and variables using future functions.
  526.  
  527.   format Pointer to a string holding the format string for this function.
  528.         Note that FPL_ARGLIST is expanded so that every letter match one of
  529.         the FPL_xxxARG defines. When using FPL_OPTARG, use this information
  530.         to see which kind of argument you have recieved.
  531.  
  532.   funcdata This is the same pointer as specified in fplAddFunction()'s tag
  533.            FPLTAG_FUNCDATA or NULL if the tag wasn't used.
  534.  
  535.   ret   The kind of the expected return code. Only really interesting for
  536.         functions declared with optional return types. If this is different
  537.         than FPL_OPTARG, you do better to return that type, or if that type
  538.         isn't what you wanted, return a FPL syntax error code!!!
  539.  
  540.   variable If this is a variable-read, this structure field will hold the
  541.         current [default] value of this variable. For strings, its a regular
  542.         FPL-string (with the length readable through the common macro
  543.         'FPL_STRLEN()') and for integers a regular long.
  544.  
  545. 14.    Interface function
  546.  
  547.   Whenever this function is called, you know that the library has found one of
  548. your  functions  or variables in the FPL program, discovered an error or wants
  549. an answer to a question. You should respond to such a call as fast as
  550. possible.
  551.  
  552.   When this function is called, all registers (d2-d7, a2-a6) will be set to
  553. the same values as when you called fplInit(). Therefore, "__saveds", "__geta4"
  554. or "geta4();" won't be necessary in all standard cases. Note that the
  555. parameter is sent in register A0.
  556.  
  557.   The interface function is specified as the first parameter in the fplInit()
  558. call. The function is declared as:
  559.  
  560.      int __asm InterfaceFunction ( register __a0  struct fplArgument *);
  561.  
  562.    Returning data to FPL   strings, ints, chars and such
  563.    Errors to interpreter   error code from you
  564.    Argument structure      what can I read from where
  565.    Example functions       how can this be done
  566.    Reserved exception IDs  questions from the interpreter
  567.  
  568. 15.    Reserved exception IDs
  569.  
  570.   The interface function is used not only to activate user declared functions,
  571. but to answer and react to the special reservd messages that the FPL
  572.  
  573.                                   - Page 8 -
  574. 15.    Reserved exception IDs
  575.  
  576. interpreter can send it in certain conditions. FPL reqruies a two way
  577. communication and this is the way it speaks to you. You answer to FPL by
  578. calling fplSend() with proper paramters.
  579.  
  580. These messages are using negative IDs which are read in the argument
  581. structure.
  582.  
  583. - FPL_GENERAL_ERROR:
  584.   FPL has found an error in the executed FPL program. The error code is to be
  585.   found in the ->argv[0] member! Do not send back any return value, they are
  586.   just ignored!
  587.  
  588. - FPL_FILE_REQUEST:
  589.   A file containing an exported function has been flushed from memory
  590.   and now FPL wants it back (someone called it). The ->argv[0] contains
  591.   the filename of the program. FPL wants the answer in the
  592.   FPLSEND_PROGRAM or FPLSEND_PROGFILE tag of a fplSend() call. If none
  593.   of these messages is sent, the program will fail with "internal
  594.   error".
  595.  
  596. - FPL_FLUSH_FILE:
  597.   When using non-cached files which is started with fplExecuteScript()
  598.   and declares global symbols, FPL will tell you by sending this that
  599.   it is ok for you to flush this file from memory now if you want.
  600.   If you decide to remove it, tell FPL by the {FPLSEND_CONFIRM, true}
  601.   tag of fplSend(). ->argv[0] contains the filename
  602.   of the program. If you don't reply with that tag, you must not do anything
  603.   to the function's program area!
  604.   This might be called after a FPLSEND_FLUSHFILE call.
  605.  
  606. - FPL_WARNING:
  607.   Whenever the FPL interpreter finds an error that it might be able to pass,
  608.   it calls the interface function with this ID set. If a
  609.   fplSend(FPLSEND_CONFIRM, TRUE) is sent, the error will be ignored and the
  610.   interpreter keeps on working!
  611.  
  612.   Any warning reported in this way is a proof of incorrect coding in the FPL
  613.   program. The errors should be instantly fixed as soon as possible. The
  614.   interpreter can not be expected to always continue as the program should
  615.   have done if it was written correct. The interpreter guesses and tries one
  616.   or a few ways to continue. Those ways may _not_ be the ones that the FPL
  617.   programmer desired when he wrote the failing program!
  618.  
  619.   Warnings caused by an error such as "a[2[=3;" will fail in a
  620.   FPL_MISSING_BRACKET at the position right after the number "2". If you
  621.   ignore such a failure, FPL will try to continue running on that position
  622.   which only will cause a dead end FPL_SYNTAX_ERROR instead. The FPLSEND_STEP
  623.   tag is done to be used in such occasions.
  624.  
  625.   A very important detail to remember when you decide to correct the FPL
  626.   program, is that any global symbols that might be cached from that file
  627. must
  628.   be cleared and re-initialized!
  629.  
  630.   The return code of this function is ignored!
  631.  
  632. - FPL_UNKNOWN_FUNCTION:
  633.  
  634.   This can only happen if the FPLTAG_ALLFUNCTIONS has been specified. When
  635.   this ID is received, it means that FPL has interpreted a function that it
  636.   didn't recognize, it is unknown. FPL have parsed the arguments as usual and
  637.   they can all be read as usual. A good habit in this case (if not any other)
  638.   is to check the ->format member of the argument structure, to see which
  639.   kinds of arguments that are received.
  640.  
  641.   ->funcdata is reserved for future use in this case, and should not be used
  642.   as if it contained anything.
  643.  
  644.                                   - Page 9 -
  645. 15.    Reserved exception IDs
  646.  
  647.  
  648.   To return a return code to FPL, use the fplSend() as usual. Notice that it
  649.   can be really tricky to know which kind you should return! Is it a string
  650. or
  651.   is it an int?
  652.  
  653.   If you don't send anything, FPL will try to guess which kind of value that
  654.   should be returned. Default is 'int'.
  655.  
  656.   The return code of this function is returned to FPL as the standard FPL
  657.   error code. Return zero for success!
  658.  
  659. 16.    Returning error codes to the FPL interpreter
  660.  
  661.   Each call to the interface function will have a final "return" call. The
  662. return code will be the source of progress information to the interpreter. If
  663. zero is returned, everything went ok, but if anything else than that was
  664. returned from you FPL will fail and return that error on the current interpret
  665. position! You will find proper return codes to return in the <libraries/FPL.h>
  666. file. Of course you can return any value you please, but FPL will only
  667. understand the codes from that file.
  668.  
  669.   Do not mix this return code with the return procedure when returning things
  670. to FPL.
  671.  
  672.   For assembler programmers: the return code is of course always return in D0.
  673.  
  674. 17.    Sending data to FPL
  675.  
  676.  
  677.  The function that FPL found - that you have defined as a function (by calling
  678. fplAddFunction()) - requires a return value.
  679.  
  680.  When you've done with doing what you should do, you should send to FPL what
  681. you specified that this function should return.
  682.  
  683.     Sending an int
  684.     ~~~~~~~~~~~~~~
  685.         unsigned long tags[]={FPLSEND_INT, code, FPLSEND_DONE};
  686.         fplSend(arg->key, tags);
  687.  
  688.     Sending a string
  689.     ~~~~~~~~~~~~~~~~
  690.         unsigned long tags[]={FPLSEND_STRING, string,
  691.                               FPLSEND_STRLEN, length_of_string,
  692.                               FPLSEND_DONE};
  693.         fplSend(arg->key, tags);
  694.  
  695.  FPL will copy the string at the function call, which makes it perfectly legal
  696. to free or re-use the string immediately after the function call. Sending a
  697. NULL pointer is legal and will result in an zero length string.
  698.  
  699.  If you set FPLSEND_STRLEN to -1 (or skip the tag), FPL will make a strlen()
  700. on the string to get the length of it.
  701.  
  702.  If the length of the string you want to send back to FPL is zero, it's OK to
  703. simply ignore the sending, send a NULL pointer or send a zero length string.
  704. All ways will cause the same result.
  705.  
  706.  See also  return codes to FPL interpreter .
  707.  
  708. 18.    Example
  709.  
  710.   Let's look at a small example. We have specified a few functions.
  711.  
  712. output() function requires a string as argument (S), outputs the string and
  713. returns zero.
  714.  
  715.                                  - Page 10 -
  716. 18.    Example
  717.  
  718.  
  719. double() requires an integer as argument (I) and return twice the input
  720. number.
  721.  
  722. get() takes no argument (NULL) and returns a string.
  723.  
  724. printf() takes a string and an list of optional parameters (So>) and performs
  725. a regular C language printf() operation!! Returns the number of printed
  726. characters.
  727.  
  728.    #include <proto/FPL.h>
  729.    long fplSendTags(void *, unsigned long, ...);
  730.  
  731.    long __asm InterfaceFunction( register __a0  struct fplArgument 
  732. *argument)
  733.    {
  734.      APTR string;
  735.      switch(argument->ID) {
  736.      case OUTPUT:                       /* handle output() */
  737.         fplSendTags(argument->key,
  738.                     FPLSEND_INT, printf("%s", argument->argv[0],)
  739.                     FPLSEND_DONE);
  740.         break;
  741.  
  742.      case PRINTF:
  743.         fplSendTags(argument->key,
  744.                     FPLSEND_INT, vprintf(arg->argv[0], (char *)&arg->argv[1])
  745.                     FPLSEND_DONE);
  746.         break;
  747.  
  748.      case DOUBLE:                       /* handle double() */
  749.         fplSendTags(argument->key,
  750.                     FPLSEND_INT, (int)argument->argv[0]*2,
  751.                     FPLSEND_DONE);
  752.         break;
  753.  
  754.      case GET:                          /* handle get() */
  755.         string=fplAllocString(argument->key, 100); /* Allocate memory */
  756.         strcpy(string, GetThatString());/* Get the string */
  757.  
  758.         fplSend(argument->key,
  759.                 FPLSEND_STRING, string,
  760.                 FPLSEND_STRLEN, -1, /* let FPL make a strlen() */
  761.                 FPLSEND_DONTCOPY_STRING, TRUE, /* go ahead use my string! */
  762.                 FPLSEND_DONE);
  763.         break;
  764.  
  765.      case FPL_GENERAL_ERROR:            /* error handling */
  766.         {
  767.           char buffer[FPL_ERRORMSG_LENGTH];
  768.           long col;
  769.           char *name;
  770.           fplSendTags(arg->key,
  771.                   FPLSEND_GETCOLUMN, &col,
  772.                   FPLSEND_GETPROGNAME, &name,
  773.                   FPLSEND_DONE);
  774.           printf("\n>>> %s\n",
  775.                      fplGetErrorMsg(arg->key, (long)arg->funcdata, buffer));
  776.           printf(">>> Byte position %d in file \"%s\".\n", col, name);
  777.         }
  778.        break;
  779.      }
  780.  
  781.      return 0;
  782.    }
  783.  
  784.    long fplSendTags(void *anchor, unsigned long tags, ...)
  785.  
  786.                                  - Page 11 -
  787. 18.    Example
  788.  
  789.    {
  790.      return(fplSend(anchor, &tags));
  791.    }
  792.  
  793. 19.    Interval function
  794.  
  795.   This function will be called a lot of times. About once for every statement
  796. FPL interprets. It _must_ be coded in consideration of execution speed.
  797. Returning anything but zero breaks the program execution. The returned value
  798. is later readable by calling fplSend() with the FPLSEND_GETRESULT tag.
  799.  
  800.   The argument to this function is received in register A0 and points to the
  801. data you could specify in the FPLTAG_USERDATA tag of fplInit(), or NULL. All
  802. registers (d2-d7, a2-a6) will have the same contents as when you called
  803. fplInit(). Therefore, "__saveds" is hardly needed.
  804.  
  805. In this example we have a function called any_keypress() which checks if any
  806. breaking key has been pressed since last check:
  807.  
  808.    long __asm IntervalFunction(register __a0 void *userdata)
  809.    {
  810.      return(any_keypress()); /* break if a key was pressed! */
  811.    }
  812.  
  813. Breaking the execution from the interval function will cause the library to
  814. return the error code FPL_PROGRAM_STOPPED.
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.                                  - Page 12 -
  858. 19.    Interval function
  859.  
  860.  
  861. 20.    INDEX of sections
  862.  
  863. Adding functions to FPL ............................................   4. 47
  864. Argument ...........................................................   6. 47
  865. Errors .............................................................   5. 25
  866. Example ............................................................   9. 60
  867. FPL Library Documentation ..........................................   1.  0
  868. fplInit() calling ..................................................   4. 60
  869. Funclib overview ...................................................   1. 23
  870. Important note .....................................................   2. 55
  871. Interface function .................................................   7. 39
  872. Interval function ..................................................  11.  3
  873. Memory functions ...................................................   5. 58
  874. Multi files concepts ...............................................   2.  5
  875. Reserved exception IDs .............................................   7. 62
  876. Returning error codes to the FPL interpreter .......................   9. 11
  877. Sending data to FPL ................................................   9. 26
  878. Step by step .......................................................   3. 63
  879. Survey .............................................................   3. 44
  880. Using FPL in software ..............................................   1. 47
  881. Your functions .....................................................   5. 51
  882.  
  883. 21.    INDEX of keywords
  884.  
  885.  adding functions to FPL  ..........................................   4. 11
  886.  Argument structure      ...........................................   7. 59
  887.  Coding hints         ..............................................   1. 16
  888.  Custom functions     ..............................................   1. 18
  889.  Error exceptions     ..............................................   1. 17
  890.  Errors to interpreter   ...........................................   7. 58
  891.  Example functions       ...........................................   7. 60
  892.  exit()  ...........................................................   4. 40
  893.  Expressions  ......................................................   3. 47
  894.  FPL programming!  .................................................   1.  8
  895.  fplArgument  ......................................................   4. 31
  896.  fplInit  ..........................................................   6. 43
  897.  FPLTAG_INTERNAL_ALLOC  ............................................   6. 11
  898.  FPLTAG_INTERNAL_DEALLOC  ..........................................   6. 10
  899.  FPL_GENERAL_ERROR  ................................................   4. 46
  900.  FPL_REQUEST_FILE  .................................................   5. 40
  901.  FrexxWare  ........................................................   1.  3
  902.  Funclib overview     ..............................................   1. 22
  903.  function  .........................................................   3. 51
  904.  functions  ........................................................   7. 43
  905.  Implement guide      ..............................................   1. 15
  906.  interface function  ...............................................   4. 13
  907.  interfaceFunction  ................................................   6. 43
  908.  interval function  ................................................   3. 49
  909.  Interval function   ...............................................   5. 56
  910.  keyword  ..........................................................   4. 40
  911.  keywords  .........................................................   3. 48
  912.  Memory functions    ...............................................   5. 57
  913.  Multi file concepts  ..............................................   1. 14
  914.  reserved exception IDs  ...........................................   6. 62
  915.  reserved messages  ................................................   4. 15
  916.  return codes to FPL interpreter  ..................................   9. 59
  917.  Returning data to FPL   ...........................................   7. 57
  918.  struct fplArgument  ...............................................   7. 55
  919.  Survey               ..............................................   1. 13
  920.  Using in software    ..............................................   1. 19
  921.  variables  ........................................................   3. 47
  922.  without warranty  .................................................   1.  5
  923. Call the fplInit() function with proper arguments.  ................   4.  6
  924.